package cream.alarm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cream.alarm.activity.WeekdayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SimpleAdapter;

public class WeekdayAlarmActivity extends ListActivity {
	private final static String TAG = "WeekdayAlarmActivity";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 不显示程序的标题栏
		requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);

		setContentView(R.layout.main);

		// TextView timerText = (TextView) findViewById(R.id.time);
		// TextView repeatInfo = (TextView) findViewById(R.id.repeat_info);
		// TextView label = (TextView) findViewById(R.id.label);

		Map<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("time", "06:00");
		dataMap.put("repeatInfo", "EveryDay");
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		data.add(dataMap);

		setListAdapter(new SimpleAdapter(this, data, R.layout.alarm_list_row,
				new String[] { "time", "repeatInfo" }, new int[] { R.id.time,
						R.id.repeat_info }));

		getListView().setTextFilterEnabled(true);
		// timerText.setText("miao");
		// repeatInfo.setText("repeat");
		// label.setText(">");
	}

	// 创建菜单键按钮事件
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		Log.d(TAG, "Creating option menu");
		menu.add(Menu.NONE, Menu.NONE, Menu.FIRST,
				R.string.option_menu_list_weekday);

		return super.onCreateOptionsMenu(menu);
	}

	// 菜单项被选中
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getOrder() == Menu.FIRST) {
			Intent i = new Intent();
			i.setClass(WeekdayAlarmActivity.this, WeekdayList.class);
			startActivityForResult(i, 0);
		}
		return super.onOptionsItemSelected(item);
	}

	// 由其他 Activity 页面返回
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// do something
	}

}